import QuestSpawn from "../QuestSpawn";
import GameUtil from "../../Fantasy/Util/GameUtil";
const {ccclass, property} = cc._decorator;

@ccclass
export default class WrongNodeJs extends cc.Component {

    @property(cc.Node)
    errorNode:cc.Node = null;
    @property(cc.Node)
    tipNode:cc.Node = null;
    @property(cc.Node)
    NoMore:cc.Node = null;
    @property(cc.Label)
    number:cc.Label = null;
    @property(cc.Node)
    toast:cc.Node = null;
    @property(cc.Node)
    last:cc.Node = null;
    @property(cc.Node)
    next:cc.Node = null;
    currNumber;
    wrongQuestArr
    questArr;
    onLoad () {
        if(QuestSpawn.wrongArr.length <= 0){
            this.toast.active = true;
            this.last.active = false;
            this.next.active = false;
        }else{
            this.currNumber = 1;
            QuestSpawn.setIsWrong(true);
            this.wrongQuestArr = QuestSpawn.wrongArr;
            this.updateNumber();
            Log("错题的数量：",this.wrongQuestArr.length,"数组：",this.wrongQuestArr);
            this.errorNode.removeAllChildren();
            for(let i = 0;i< this.wrongQuestArr.length;i++){
                Log("第几个",i);
                this.wrongQuestArr[i].parent = this.errorNode;
                this.wrongQuestArr[i].active = false;
    
            }
            this.questArr = this.errorNode.children;
            this.disPlay(this.currNumber);
        }
    }
    updateNumber(){
        this.number.getComponent(cc.Label).string = this.currNumber+""+"/"+this.wrongQuestArr.length+"";
    }
    disPlay(index){
        for(let i = 0;i< this.questArr.length;i++){
            this.questArr[i].active = false;
        }
        this.questArr[index-1].active = true;
        
    }



    btnCallback(target,data){
        if(data == "closeWrong"){
            this.node.destroy();
        }else if(data == "closeTip"){
            this.tipNode.active = false;
        }else if(data == "closeMore"){
            this.NoMore.active = false;
        }else if(data == "continue"){
            if(QuestSpawn.isContest == true){
                Log("竞技场操作");
                if(this.node){
                    this.node.destroy();
                }
            }else{
                GameUtil.gotoScene("MainScene");
            }
        }else if(data == "next"){
            if(this.currNumber >this.questArr.length-1 ){
                Log("没有更多了");
                this.NoMore.active = true;
            }else{
                this.currNumber ++;
                this.disPlay(this.currNumber);
                this.updateNumber();
            }
        }else if(data == "back"){
            if(this.currNumber < 2){
                Log("没有更多了");
                this.NoMore.active = true;
            }else{
                this.currNumber --;
                Log("错误的题目",this.currNumber)
                this.disPlay(this.currNumber);
                this.updateNumber();
            }
        }
    }

    start () {

    }

    // update (dt) {}
}
